<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2019/1/18
  Time: 23:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>收藏表</title>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css">
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>
<div class="demoTable">
    <div class="layui-inline">
        <input type="text" class="layui-input" placeholder="收藏编号查询" name="id" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">查询</button>
    <button type="button"  class="layui-btn"   onclick="add()">新增收藏</button>
    <button class="layui-btn " data-type="isDele" >批量删除</button>
    <button class="layui-btn " data-type="outComcollect" >导出</button>
    <button type="button"  class="layui-btn"   onclick="inComcollect()" >导入</button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-sm" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>
<script src="/layuiadmin/layui/layui.js" charset="utf-8"></script>

<script>

    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/uploadCom/' //上传接口
            ,done: function(res){
                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'/comcollect'
            /* ,limit:6  //每页显示数*/
            ,height: 420
            ,toolbar: '#toolbarDemo'
            ,title: '收藏表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                /* ,{field:'cid', title:'ID', width:80, fixed: 'left',unresize: true, sort: true}*/
                ,{field:'ctId', title:'商品收藏id', width:180,sort: true}
                ,{field:'UId', title:'会员id', width:180,sort: true}
                ,{field:'wareId', title:'商品id ', width:180,sort: true}
                ,{field:'uNickName', title:'会员昵称', width:180,sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
            ]]
            ,page: true
            ,id:'testReload'
        });


        //监听单元格编辑
        table.on('edit(test)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layer.msg('[ID: '+ data.id +'] ' + field + ' 信息：'+ value);
        });
        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'update'){
                parent.layer.open({
                    title:'修改',
                    maxmin:true,
                    type:2,
                    content:'/uploadCom?ctId='+obj.data.ctId,
                    area:['650px','600px'],
                    end:function   () {
                        location.reload();
                    }
                })
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    window.location.href="/deleteCom?type="+"delete"+"&ctId="+obj.data.ctId;
                });
            } else if(obj.event === 'watch'){
                //打开弹出框
                parent.layer.open({
                    title:'商品详情',
                    maxmin:true,
                    type:2,
                    content:'/ComcollectGoodsServlet?ctId='+obj.data.ctId,
                    area:['900px','600px'],
                    end:function   () {
                        location.reload();
                    }
                });
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('testReload');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
            ,isDele: function(){//批量删除
                layer.confirm('真的删除选中行么', function(index) {
                    var checkStatus = table.checkStatus('testReload')
                        , data = checkStatus.data;
                    var objs = eval(data);
                    if(objs.length!=null&&""!=objs.length) {
                        var str = "";
                        for (var j = 0; j < objs.length; j++) {
                            if (j == 0) {
                                str = str + objs[j].ctId;
                            } else {
                                str = str + "," + objs[j].ctId;
                            }
                        }
                        window.location.href = "/deleteCom?type="+"deleteAll"+"&str="+str;
                    }else{
                        alert("请选中后,再删除！")
                        window.location.href = "/jsp/dcb/Comcollect.jsp";
                    }
                })
            }


            ,outComcollect: function(){//导出
                layer.confirm('是否导出选中行', function(index) {
                    var checkStatus = table.checkStatus('testReload')
                        , data = checkStatus.data;
                    var objs = eval(data);
                    if(objs.length!=null&&""!=objs.length) {
                        var str = "";
                        for (var j = 0; j < objs.length; j++) {
                            if (j == 0) {
                                str = str + objs[j].ctId;
                            } else {
                                str = str + "," + objs[j].ctId;
                            }
                        }
                        window.location.href="/outCom?code=Comcollect"+"&str="+str;
                    }else{
                        alert("请选择要导出的行")
                        window.location.href = "/jsp/dcb/Comcollect.jsp";
                    }
                })
            }

            ,reload: function(){
                var ctId = $('#demoReload');
                var uNickName = $('#demoReload1');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        ctId:ctId.val(),
                        uNickName: uNickName.val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
<script>

    //提示增加成功.和删除成功和修改
    function tishi() {
        var info ="${requestScope.msg}";
        if(info !=null && info!=""){
            alert(info);
            info="";
            window.location.href = "/jsp/dcb/Comcollect.jsp";
        }
    }
    tishi();


    function inComcollect() {
        parent.layer.open({   //打开一个弹出层
            title:'导入信息',   //弹出层的标题
            maxmin:true,
            type:2,
            content:'/jsp/dcb/inComcollect.jsp', //要访问的地址
            area:['800px','600px'],
            end:function   () { //表示弹出层关闭的时候的代码块
                location.reload();
            }
        });
    }

    //新增收藏
    function add() {
        parent.layer.open({   //打开一个弹出层
            title:'新增收藏',   //弹出层的标题
            maxmin:true,
            type:2,
            content:'/jsp/dcb/addComcollect.jsp', //要访问的地址
            area:['800px','600px'],
            end:function   () { //表示弹出层关闭的时候的代码块
                location.reload();
            }
        });
    }
</script>
</body>
</html>
